package com.sample.dto;

import java.io.Serializable;
import java.util.List;

import com.alibaba.fastjson.annotation.JSONField;
import com.sample.entity.Order;
import com.swak.Constants;
import com.swak.entity.Page;
import com.swak.persistence.Classify;
import com.swak.security.Principal;
import com.swak.utils.Lists;
import com.swak.utils.bean.BeanCopier;
import com.swak.utils.bean.BeanCopiers;

import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

/**
 * 描述
 * 
 * @author Auto Generator
 * @date 2022-04-21T20:47:07.509267200
 */
@Getter
@Setter
@Accessors(chain = true)
public class OrderDTO implements Serializable {

	private static final long serialVersionUID = 1L;

	@lombok.EqualsAndHashCode.Exclude
	@lombok.ToString.Exclude
	private static final transient BeanCopier<OrderDTO, Order> Copier = BeanCopiers.create(OrderDTO.class, Order.class);

	private Long id;
	private String name;
	private java.math.BigDecimal amount;
	private Byte state;
	private Long goodsId;
	private String goodsName;
	private Integer goodsQuantity;
	private Long userId;
	private String userName;
	@JSONField(format = Constants.Second_Format)
	private java.time.LocalDateTime createDate;
	@JSONField(format = Constants.Second_Format)
	private java.time.LocalDateTime updateDate;

	/**
	 * 操作人的身份
	 */
	private Principal principal;

	/**
	 * DTO 转换为 PO
	 *
	 * @param entity
	 * @return DTO
	 */
	public Order transform() {
		return Copier.transform(this);
	}

	/**
	 * DTOS 转换为 POS
	 *
	 * @param dtos
	 * @return DTOs
	 */
	public static List<Order> transform(List<OrderDTO> dtos) {
		List<Order> pos = Lists.newArrayList();
		if (dtos == null) {
			return pos;
		}
		for (OrderDTO dto : dtos) {
			pos.add(dto.transform());
		}
		return pos;
	}

	/**
	 * PO 转换为 DTO
	 *
	 * @param entity
	 * @return DTO
	 */
	public static OrderDTO convert(Order entity) {
		if (entity == null) {
			return null;
		}
		return Copier.convert(entity);
	}

	/**
	 * POS 转换为 DTOS
	 *
	 * @param entitys
	 * @return DTOs
	 */
	public static List<OrderDTO> convert(List<Order> entitys) {
		List<OrderDTO> dtos = Lists.newArrayList();
		if (entitys == null) {
			return dtos;
		}
		for (Order entity : entitys) {
			dtos.add(OrderDTO.convert(entity));
		}
		return dtos;
	}

	/**
	 * Page 转换为 Page
	 *
	 * @param entity
	 * @return DTO
	 */
	public static Page<OrderDTO> convert(Page<Order> page) {
		return Page.of(page.getParam(), OrderDTO.convert(page.getData()));
	}

	/**
	 * classify 分类
	 *
	 * @param dtos
	 * @param pos
	 * @return Classify
	 */
	public static Classify<Order> classify(List<OrderDTO> dtos, List<Order> pos) {
		return Classify.of(OrderDTO.transform(dtos), pos);
	}

	/**
	 * 创建DTO
	 *
	 * @return DTO
	 */
	public static OrderDTO of() {
		return new OrderDTO();
	}
}
